/**
 * @author: h'zh
 * @date: 12.14
 */
import request from '../utils/request'
import user from "../store/modules/user";

//TODO:适配各种向后端发出的请求(管理员操作)

/**
 * 这里为两个需要填充的API，请使用者自行填充归类
 * */
export function setDefaultTerm()
{

}

export function createStudent()
{

}
// =====================学生相关API
export function getStudentList(params) {
    return request({
        url: '/admin/getStudentList',
        method: 'get',
        params,

    })
}

export function updateDeleteStatus(params) {
    return request({
        url: '/admin/deleteStuBatch',
        method: 'post',
        params,
    })
}


export function updateStudent(id, data) {
    return request({
        url: '/admin/updateStudent/'+id,
        method: 'post',
        data: data
    })
}

// =========================需求相关API
export function getRequestList(params)
{
    return request({
        url:'/admin/searchRequests',
        method:'get',
        params
    })
}

export function getGoodList(params){
    return request({
        url:'/admin/searchGoods',
        method:'get',
        params
    })
}

export function searchStudent(params) {
    return request({
        url: '/admin/searchStudent',
        method: 'get',
        params
    })
}

export function updateGroup(id, data) {
    return request({
        url: '/admin/modifyGroup/' + id,
        method: 'post',
        data
    })
}

// export function deleteGroup(id) {
//     return request({
//         url: '/admin/deleteGroup/' + id,
//         method: 'post'
//     })
// }

export function createGroup(data) {
    return request({
        url: '/admin/addGroup',
        method: 'post',
        data
    })
}

export function searchGroup(groupId, keyword) {
    return request({
        url: '/admin/searchGroup/' + groupId,
        method: 'get',
        params: keyword
    })
}

// 获取小组的成员信息
export function getGroupMembers(groupId) {
    return request({
        url: '/admin/findAllUserIngroup/' + groupId,
        method: 'get'
    })
}

//删除小组的成员
export function removeUserInGroup(studentIds) {
    return request({
        url: '/admin/deleteGroupMember/',
        method: 'post',
        data: studentIds
    })
}

export function deleteGroups(groupIds) {
    return request({
        url: '/admin/deleteGroups',
        method: 'post',
        data: groupIds
    })
}

export function resetGroupPassword(groupId) {
    return request({
        url :'/admin/resetGroupPwd/'+ groupId,
        method: 'post',
    })
}

//小组归档
export function getGroupFiled(groupIds){
    return request({
        url :'admin/getGroupFiled',
        method: 'post',
        data: groupIds
    })
}

//取消归档
export function getGroupUnFiled(groupIds){
    return request({
        url :'admin/getGroupUnFiled',
        method: 'post',
        data: groupIds
    })
}

//======老师相关的API
export function getTeachers(params) {
    return request({
        url: '/admin/getAllTeacher',
        method: 'get',
        params
    })
}
export function fetchAllTeachers(params = {pageNum: 1, pageSize: -1}) {
    return request({
        url: '/admin/getAllTeacher',
        method: 'get',
        params
    })
}



export function deleteTeacher(ids) {
    return request({
        url: '/admin/deleteTeacher',
        method: 'post',
        data: ids
    })
}

export function updateTeacher(data) {
    return request({
        url: '/admin/modifyTeacher',
        method: 'post',
        data
    })
}

export function getTeacherInfo(id) {
    return request({
        url: '/admin/findTeacher/' + id,
        method: 'get'
    })
}

export function createTeacher(data) {
    return request({
        url: '/admin/addTeacher',
        method: 'post',
        data
    })
}

export function findAllGroupOfTeacher(id, term) {
    return request({
        url: '/admin/findAllGroupOfTeacher/' + id + '/' + term,
        method: 'get'
    })
}

export function resetTeacherPwd(teacherIds, pwd) {
    return request({
        url: '/admin/resetTeacherPwdBatch',
        method: 'post',
        data: {
            ids: teacherIds,
            password: pwd
        }
    })
}

// 没有属于任何老师的小组
export function getFreeGroups(params = {pageNum: 1, pageSize: -1}) {
    return request({
        url: '/admin/findAllGroupNotOfTeacher',
        method: 'get',
        params
    })
}

export function updateGroupOwnerInfo(groupIds, ownerTeacherId) {
    return request({
        url: '/admin/updateGroupOwner',
        method: 'post',
        data: {
            ownerId:ownerTeacherId,
            objectIds: groupIds
        }
    })
}



//=======商品类型相关的API
export function fetchAllTypes() {
    return request({
        url: '/admin/getAllTypes',
        method: 'get'
    })
}


export function deleteType(id) {
    return request({
        url: '/admin/deleteType/' + id,
        method: 'post'
    })
}
export function addType(data) {
    return request({
        url: '/admin/addType',
        method:'post',
        data
    })
}

export function updateType(data){
    return request({
        url: '/admin/updateType',
        method:'post',
        data
    })
}

